#!/usr/bin/perl
use strict;
use warnings;

my $setID = shift @ARGV;
if (not defined $setID or scalar @ARGV) {
    print STDERR "Usage: $0 <setID>\n";
    exit 1;
}

if ($setID !~ m/^[0-9]$/) {
    print STDERR "set ID should be one digit\n";
    exit 1;
}


my $phraseID = 1;
my $page = 1;

open PAGE, '>', "phrases-$setID-".$page++.".txt"
    or die "can't write file: $0";
print PAGE '-'x80, "\n";

while (<STDIN>) {
    chomp;
    s/^\s*//;
    s/\s*$//;
    s/\s+/ /g;

    print PAGE ' 'x77, sprintf('%s%02d', $setID, $phraseID++), "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "   $_\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE "\n";
    print PAGE '-'x80, "\n";

    if ($phraseID % 4 == 1) {
        close PAGE;

        open PAGE, '>', "phrases-$setID-".$page++.".txt"
            or die "can't write file: $0";
        print PAGE '-'x80, "\n";
    }
}

close PAGE;

